package com.stox.charting.ui.swing.presenter.delegate.builder;

import com.stox.charting.ui.swing.model.Axis;
import com.stox.charting.ui.swing.model.ChartModel;
import com.stox.charting.ui.swing.model.DefaultAxis;
import com.stox.charting.ui.swing.model.Orientation;
import com.stox.charting.ui.swing.model.price.DateAxis;
import com.stox.charting.ui.swing.model.price.IBarAxis;
import com.stox.charting.ui.swing.model.price.InfoAxis;
import com.stox.charting.ui.swing.view.ChartView;
import com.stox.core.model.IBar;

public class AxisBuilder {

	@SuppressWarnings("unchecked")
	public <T extends Axis> T build(Class<T> clazz, ChartView chartView, 
			Orientation orientation, String borderLayoutConstraints, 
			ChartModel<?> chartModel){
		if(clazz.isAssignableFrom(IBarAxis.class)){
			return (T) new IBarAxis(chartView, orientation, borderLayoutConstraints, (ChartModel<? extends IBar>) chartModel);
		}else if(clazz.isAssignableFrom(InfoAxis.class)){
			return (T) new InfoAxis(chartView, orientation, borderLayoutConstraints, (ChartModel<? extends IBar>) chartModel);
		}else if(clazz.isAssignableFrom(DefaultAxis.class)){
			return (T) new DefaultAxis(chartView, orientation, borderLayoutConstraints);
		}else if(clazz.isAssignableFrom(DateAxis.class)){
			return (T) new DateAxis(chartView, orientation, borderLayoutConstraints, (ChartModel<? extends IBar>) chartModel);
		}
		return null;
	}
	
}
